package com.health.fragment.focusgroup.maternity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.FWMYDPJActivity;
import com.health.NovaApplication;
import com.health.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.focusgroup.MaternityActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.GRAVIDA_BASEINFO;
import com.health.tablebean.GRAVIDA_FIRSTFOLLOWUP;
import com.health.tablebean.GRAVIDA_PRE_ASSISTCHECK;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

/**
 * 重点人群-- 孕妇---产前随访1
 *
 * @author nova
 */
public class Maternity_Cqsf1Fragment extends NovaFragment implements onFragmentSave, OnClickListener {
    private final static String TAG = "Maternity_Cqsf1Fragment";
    private View cqsfView = null;
    private FDbManager fdbmanger = null;

    // ------------------------------基本信息-----------------------------
    private EditTextWithDate ed_date;
    private EditText ed_age;
    private EditText ed_zq;// 周期

    private EditText ed_ycfm;// 孕次分娩
    private EditText ed_ydfw;// 阴道分娩

    private EditText ed_pgc;// 剖宫产
    /**
     * 末次月经时间
     */
    private EditTextWithDate ed_mcyj_date;// 末次月经时间
    private EditTextWithDate ed_ycq_date;// 预产期
    private MyGridView gd_jws;// 既往史
    private MyGridView gd_jzs;// 家族史
    private MyGridView gd_grs;// 个人史
    private MyGridView gd_fksss;// 妇科手术史
    private MyGridView gd_xz;// 心脏
    private MyGridView gd_fb;// 肺部
    private MyGridView gd_wy;// 外阴
    private MyGridView gd_yd;// 阴道
    private MyGridView gd_gj;// 宫颈
    private MyGridView gd_zg;// 子宫
    private MyGridView gd_fj;// 附件
    private EditText ed_ycs_zrlc;//自然 流产
    private EditText ed_ycs_rglc;//人工流产
    private EditText ed_ycs_st;// 死胎
    private EditText ed_ycs_sw;// 死亡
    private EditText ed_ycs_xsesw;// 新生儿死亡
    private EditText ed_ycs_csqx;// 出生缺陷
    private EditText ed_zfxm;// 丈夫姓名
    private EditText ed_zfnl;// 丈夫年龄
    private EditText ed_zfdh;// 丈夫电话
    // private EditText ed_yc;// 孕次

    private String str_zzId = "";

    private String str_mcyjId = "";

    private EditText ed_sg;// 身高

    private EditText ed_weight;// 体重
    private EditText ed_bmi;// BMI
    private Button btn_choose_weight;// 选择体重

    private EditText ed_xy;
    private Button btn_choose_xy;

    // ------------------------------辅助检查---------------------------------

    private EditText ed_xhdbz;// 血红蛋白值
    private Button btn_choose_xhdbz;
    private EditText ed_bxb;// 白细胞
    private EditText ed_xxb;// 血小板

    private EditText ed_xcg_qt;// 血常规其他
    private EditText ed_jcg;// 尿常规

    private Button btn_choose_jcg;// 选择尿常规
    private EditText ed_jcg_qt;// 尿常规其他
    private EditText ed_xx;// 血型
    private EditText ed_rh;// RH
    private EditText ed_xt;// 血糖
    private Button btn_choose_xt;// 选择血糖
    private EditText ed_xqgbzam;// 血清谷丙转氨酶：
    private EditText ed_xqgczam;// 血清谷草转氨酶
    private EditText ed_xdb;// 血蛋白
    private EditText ed_zdhs;// 总胆红素
    private EditText ed_zhdhs;// 综合胆红素：
    private EditText ed_xqjg;// 血清肌酐
    private EditText ed_xnsd;// 血尿素氮
    private MyGridView gd_ydfmw;// 阴道分泌物
    private MyGridView gd_mdxqsy;// 梅毒血清试验

    private MyGridView gd_hiv;// HIV抗体检测
    private EditText ed_bc;// B超

    private MyGridView gd_ztpg;// 总体评估
    private MyGridView gd_bjzd;// 保健指导
    private EditText ed_jg_ys;// 机构及科室
    private RadioGroup rd_zz;// 是否转诊
    private RadioButton rb_w;
    private RadioButton rb_y;

    private RadioGroup rd_mcyj;// 末次月经
    private RadioButton rb_mq;// 明确
    private RadioButton rb_bx;// 不详

    private EditTextWithDate ed_xcsfsj;// 下次随访时间
    private NiceSpinner ed_sfysqm;// 随访医生签名

    // ----------------------------------------------------------------------
    private RadioButtonAdapter adapter_mdxqsy = null;
    private RadioButtonAdapter adapter_hiv = null;
    private RadioButtonAdapter adapter_fksss = null;
    private RadioButtonAdapter adapter_ztpg = null;

    private CheckBoxAdapter adapter_jws = null;
    private CheckBoxAdapter adapter_jzs = null;
    private CheckBoxAdapter adapter_grs = null;
    private CheckBoxAdapter adapter_ydfmw = null;
    private CheckBoxAdapter adapter_bjzd = null;

    private RadioButtonAdapter adapter_xz = null;
    private RadioButtonAdapter adapter_fb = null;
    private RadioButtonAdapter adapter_wy = null;
    private RadioButtonAdapter adapter_yd = null;
    private RadioButtonAdapter adapter_gj = null;
    private RadioButtonAdapter adapter_zg = null;
    private RadioButtonAdapter adapter_fj = null;

    // 乙型肝炎五项:
    private RadioButtonAdapter adapter_yxgybmky;
    private RadioButtonAdapter adapter_yxgybmkt;
    private RadioButtonAdapter adapter_yxgyeky;
    private RadioButtonAdapter adapter_yxgyekt;
    private RadioButtonAdapter adapter_yxgyhxkt;
    private MyGridView mgv_yxgybmky;
    private MyGridView mgv_yxgybmkt;
    private MyGridView mgv_yxgyeky;
    private MyGridView mgv_yxgyekt;
    private MyGridView mgv_yxgyhxkt;
    private Button btn_cal_bmi;
    private NiceSpinner nice_spinner_ydqjd;
    private TextView tv_name;

    public ARCHIVE_BASEINFO userInfo;
    private List<BD_DD_INFO> qjd_list = new ArrayList<BD_DD_INFO>();
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private EditText ed_zzyy;

    private String xxId = "";
    private String rhId = "";
    private GRAVIDA_BASEINFO gravida_baseInfo;// 孕妇信息
    private TextView tv_cc;//产次

    @SuppressLint("InflateParams")
    @Override
    public View findViews(LayoutInflater inflater) {
        fdbmanger = NovaApplication.fdbmanger;
        userInfo = NovaApplication.getUserInfo();
        cqsfView = inflater.inflate(R.layout.maternity_cqsf1, null);
        initViews(cqsfView);
        NovaApplication.dbManger.addColumnByBySQL("GRAVIDA_FIRSTFOLLOWUP", "InducedABORTIONINFO");
        GlobalConts.setMaxLength(20, ed_xy);// 血压
        GlobalConts.setMaxLength(3, ed_ycs_zrlc, // 自然流产
                ed_ycs_rglc, // 人工流产
                ed_ycs_st, // 死胎
                ed_ycs_sw, // 死亡
                ed_ycs_xsesw, // 新生儿死亡
                ed_ycs_csqx);// 出生缺陷

        GlobalConts.setMaxLength(10, ed_xhdbz, // 血红蛋白值
                ed_bxb, // 白细胞
                ed_xt, // 血糖
                ed_xxb, ed_xqgbzam, // 血清谷丙转氨酶：
                ed_xqgczam, // 血清谷草转氨酶
                ed_xdb, // 血蛋白
                ed_zdhs, // 总胆红素
                ed_zhdhs, // 综合胆红素：
                ed_xqjg, // 血清肌酐
                ed_xnsd, // 血尿素氮
                ed_jg_ys// 机构及科室
        );// 血小板
        GlobalConts.setMaxLength(50, ed_jcg_qt, // 尿常规其他
                ed_bc, // B超
                ed_xcg_qt);// 血常规其他

        // GlobalConts.setMaxLength(10, ed_xhdb, // 血红蛋白
        // ed_jg_ys);// 机构
        // GlobalConts.setMaxLength(50, ed_qtfzjc);// 其他辅助检查
        // 既往史其他10
        // 家族史其他10
        // 个人史其他10
        // 妇科手术史其他50
        // 听诊其他：50
        // 妇科信息其他：50
        // 引导分泌物:50
        // 总体评估:50
        // 保健指导其他：50
        // 转诊原因：50
        getHost();

        return cqsfView;
    }

    @Override
    public void setupView(View view) {

    }

    /**
     * 设置丈夫信息
     *
     * @author 王婷婷
     * @date 2016年2月2日 下午4:14:35
     */
    public void setHusbandInfo() {
        gravida_baseInfo = NovaApplication.gravida_baseInfo;

        if (gravida_baseInfo != null) {
            ed_zfnl.setText(gravida_baseInfo.getHUSBANDAGE());
            ed_zfxm.setText(gravida_baseInfo.getHUSBAND_NAME());
            ed_zfdh.setText(gravida_baseInfo.getHUSBAND_PHONE());
        }
    }

    @Override
    public void addListener() {
        btn_choose_xhdbz.setOnClickListener(this);
        btn_choose_xy.setOnClickListener(this);
        btn_choose_weight.setOnClickListener(this);
        btn_choose_xt.setOnClickListener(this);
        btn_choose_jcg.setOnClickListener(this);
        btn_cal_bmi.setOnClickListener(this);
        rd_zz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_w) {
                    str_zzId = "DM01-11_1";
                    ed_zzyy.setText("");
                    ed_jg_ys.setText("");
                    ed_zzyy.setEnabled(false);
                    ed_jg_ys.setEnabled(false);

                } else if (checkedId == R.id.rb_y) {
                    str_zzId = "DM01-11_2";
                    ed_zzyy.setEnabled(true);
                    ed_jg_ys.setEnabled(true);
                } else {
                    str_zzId = "";
                }

            }
        });

        rd_mcyj.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_mq) {
                    str_mcyjId = "DM06-2_0";
                    ed_mcyj_date.showDialog(true);

                } else if (checkedId == R.id.rb_bx) {
                    str_mcyjId = "DM06-2_2";
                    ed_mcyj_date.setText("");
                    ed_mcyj_date.showDialog(false);
                } else {
                    str_mcyjId = "";
                }

            }
        });
    }

    @Override
    public void setData() {
        List<GRAVIDA_BASEINFO> gradicas = fdbmanger.findAllByWhere(GRAVIDA_BASEINFO.class,
                "IDCARD = '" + userInfo.getIDCARD() + "'");
        if (gradicas != null && gradicas.size() > 0) {
            gravida_baseInfo = gradicas.get(0);
            if (!TextUtils.isEmpty(gravida_baseInfo.getFetusTimes())) {
                List<BD_DD_INFO> bd_cc = getBDById(gravida_baseInfo.getFetusTimes());
                if (bd_cc != null) {
                    tv_cc.setText(bd_cc.get(0).getDATAINFO());
                }
            }
        }
        bindDdata("梅毒血清试验", "PARENTID='DM06-7'");
        bindDdata("HIV检测", "PARENTID='DM06-8'");
        bindDdata("既往史", "PARENTID='DM01-23'");
        bindDdata("家族史", "PARENTID='DM01-24'");
        bindDdata("个人史", "PARENTID='DM01-25'");
        bindDdata("妇科手术史", "PARENTID='DM01-11'");
        bindDdata("总体评估", "PARENTID='DM01-40'");
        bindDdata("保健指导", "PARENTID='DM06-03'");
        bindDdata("阴道分泌物", "PARENTID='DM06-01'");
        bindDdata("乙型肝炎五项", "PARENTID='DM06-11'");

        bindSpinner("阴道清洁度", "PARENTID='DM06-02'");
        GlobalConts.doctorList(ed_sfysqm);
        init();
        init2();
        setDateCheck();
        // adapter_bjzd.refOtherText();

    }

    /**
     * 检查是否已经填写孕次
     */
    private void checkFetusTime() {
        List<GRAVIDA_BASEINFO> gradicas = fdbmanger.findAllByWhere(GRAVIDA_BASEINFO.class,
                "IDCARD = '" + userInfo.getIDCARD() + "'");
        if (gradicas.size() > 0) {
            if (TextUtils.isEmpty(gradicas.get(0).getFetusTimes())) {
                ((MaternityActivity) getActivity()).showTextDialog("请先完善基本信息中的产次信息再进行随访操作");
                return;
            } else {
                List<BD_DD_INFO> bd_cc = getBDById(gravida_baseInfo.getFetusTimes());
                if (bd_cc != null) {
                    tv_cc.setText(bd_cc.get(0).getDATAINFO());
                }

            }
        } else {
            ((MaternityActivity) getActivity()).showTextDialog("请先完善基本信息再进行随访操作");
            return;
        }
    }

    /**
     * 通过id查询返回的数据
     *
     * @param str_id
     * @return
     * @author 王婷婷
     * @date 2015年12月15日 下午6:38:52
     */
    private List<BD_DD_INFO> getBDById(String str_id) {
        if (str_id != null) {

            List<BD_DD_INFO> bds = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "ID='" + str_id + "'");
            if (bds.size() > 0) {

                return bds;
            } else {
                return null;
            }
        } else {
            return null;
        }

    }

    private void setDateCheck() {
        // 设置时间
        GlobalConts.checkDateAfter(ed_date, ed_xcsfsj);

        // 设置预产期
        GlobalConts.checkDateAfter(ed_date, ed_ycq_date);
        // 孕周
        GlobalConts.checkNumOrange(getActivity(), ed_zq, 49, 0);
        // 孕次
        GlobalConts.checkNumOrange(getActivity(), ed_ycfm, 49, 0);
        // 阴道分娩
        GlobalConts.checkNumOrange(getActivity(), ed_ydfw, 49, 0);
        // 剖宫产
        GlobalConts.checkNumOrange(getActivity(), ed_pgc, 49, 0);
        // 身高 GlobalConts.checkNum(etHeight, 300, 1);
        GlobalConts.keep2decimal(ed_sg);
        GlobalConts.checkNumOrange(getActivity(), ed_sg, 300, 1);
        // 体重
        GlobalConts.keep2decimal(ed_weight);
        GlobalConts.checkNum(getActivity(), ed_weight, 100, 1, 999);
    }

    /**
     * 初始化布局
     *
     * @param v
     * @author 王婷婷
     * @date 2015年12月21日 上午11:10:55
     */
    private void initViews(View v) {

        rd_mcyj = (RadioGroup) v.findViewById(R.id.rd_mcyj);
        rb_mq = (RadioButton) v.findViewById(R.id.rb_mq);
        rb_bx = (RadioButton) v.findViewById(R.id.rb_bx);
        tv_name = (TextView) v.findViewById(R.id.tv_name);
        tv_name.setText("姓名：" + userInfo.getCUSTOMERNAME());
        ed_date = (EditTextWithDate) v.findViewById(R.id.ed_date);
        ed_date.setBefore(true);
        ed_age = (EditText) v.findViewById(R.id.ed_age);
        ed_zq = (EditText) v.findViewById(R.id.ed_zq);

        ed_zfxm = (EditText) v.findViewById(R.id.ed_husband_name);
        ed_zfnl = (EditText) v.findViewById(R.id.ed_husband_age);
        ed_zfdh = (EditText) v.findViewById(R.id.ed_husband_phone);

        ed_ycfm = (EditText) v.findViewById(R.id.ed_ycfm);
        ed_ydfw = (EditText) v.findViewById(R.id.ed_ydfw);

        ed_pgc = (EditText) v.findViewById(R.id.ed_pgc);
        ed_mcyj_date = (EditTextWithDate) v.findViewById(R.id.ed_mcyj_date);
        ed_ycq_date = (EditTextWithDate) v.findViewById(R.id.ed_ycq_date);
        gd_jws = (MyGridView) v.findViewById(R.id.gd_jws);
        gd_jzs = (MyGridView) v.findViewById(R.id.gd_jzs);
        gd_grs = (MyGridView) v.findViewById(R.id.gd_grs);
        gd_fksss = (MyGridView) v.findViewById(R.id.gd_fksss);
        ed_sg = (EditText) v.findViewById(R.id.ed_sg);

        ed_weight = (EditText) v.findViewById(R.id.ed_weight);
        ed_bmi = (EditText) v.findViewById(R.id.ed_bmi);
        btn_choose_weight = (Button) v.findViewById(R.id.btn_choose_weight);
        ed_xy = (EditText) v.findViewById(R.id.ed_xy);
        btn_choose_xy = (Button) v.findViewById(R.id.btn_choose_xy);

        // ---------------------------------------------------------------------
        ed_xhdbz = (EditText) v.findViewById(R.id.ed_xhdbz);
        btn_choose_xhdbz = (Button) v.findViewById(R.id.btn_choose_xhdbz);
        ed_bxb = (EditText) v.findViewById(R.id.ed_bxb);
        ed_xxb = (EditText) v.findViewById(R.id.ed_xxb);

        ed_xcg_qt = (EditText) v.findViewById(R.id.ed_xcg_qt);
        ed_jcg = (EditText) v.findViewById(R.id.ed_jcg);

        btn_choose_jcg = (Button) v.findViewById(R.id.btn_choose_jcg);
        ed_jcg_qt = (EditText) v.findViewById(R.id.ed_jcg_qt);
        ed_xx = (EditText) v.findViewById(R.id.ed_xx);
        ed_rh = (EditText) v.findViewById(R.id.ed_rh);
        ed_xt = (EditText) v.findViewById(R.id.ed_xt);
        btn_choose_xt = (Button) v.findViewById(R.id.btn_choose_xt);
        ed_xqgbzam = (EditText) v.findViewById(R.id.ed_xqgbzam);
        ed_xqgczam = (EditText) v.findViewById(R.id.ed_xqgczam);
        ed_xdb = (EditText) v.findViewById(R.id.ed_xdb);
        ed_zdhs = (EditText) v.findViewById(R.id.ed_zdhs);
        ed_zhdhs = (EditText) v.findViewById(R.id.ed_zhdhs);
        ed_xqjg = (EditText) v.findViewById(R.id.ed_xqjg);
        ed_xnsd = (EditText) v.findViewById(R.id.ed_xnsd);
        gd_ydfmw = (MyGridView) v.findViewById(R.id.gd_ydfmw);
        gd_mdxqsy = (MyGridView) v.findViewById(R.id.gd_mdxqsy);

        gd_hiv = (MyGridView) v.findViewById(R.id.gd_hiv);
        ed_bc = (EditText) v.findViewById(R.id.ed_bc);

        gd_ztpg = (MyGridView) v.findViewById(R.id.gd_ztpg);
        gd_bjzd = (MyGridView) v.findViewById(R.id.gd_bjzd);
        ed_jg_ys = (EditText) v.findViewById(R.id.ed_jg_ys);
        ed_zzyy = (EditText) v.findViewById(R.id.ed_zzyy);
        rd_zz = (RadioGroup) v.findViewById(R.id.rd_zz);
        rb_w = (RadioButton) v.findViewById(R.id.rb_w);
        rb_y = (RadioButton) v.findViewById(R.id.rb_y);
        ed_zzyy.setEnabled(false);
        ed_jg_ys.setEnabled(false);

        ed_xcsfsj = (EditTextWithDate) v.findViewById(R.id.ed_xcsfsj);
        ed_sfysqm = (NiceSpinner) v.findViewById(R.id.ed_sfysqm);

        nice_spinner_ydqjd = (NiceSpinner) v.findViewById(R.id.nice_spinner_ydqjd);

        gd_xz = (MyGridView) v.findViewById(R.id.gd_xz);
        gd_fb = (MyGridView) v.findViewById(R.id.gd_fb);
        gd_wy = (MyGridView) v.findViewById(R.id.gd_wy);
        gd_yd = (MyGridView) v.findViewById(R.id.gd_yd);
        gd_gj = (MyGridView) v.findViewById(R.id.gd_gj);
        gd_zg = (MyGridView) v.findViewById(R.id.gd_zg);
        gd_fj = (MyGridView) v.findViewById(R.id.gd_fj);

        ed_ycs_zrlc = (EditText) v.findViewById(R.id.ed_ycs_zrlc);
        ed_ycs_rglc = (EditText) v.findViewById(R.id.ed_ycs_rglc);
        ed_ycs_st = (EditText) v.findViewById(R.id.ed_ycs_st);
        ed_ycs_sw = (EditText) v.findViewById(R.id.ed_ycs_sw);
        ed_ycs_xsesw = (EditText) v.findViewById(R.id.ed_ycs_xsesw);
        ed_ycs_csqx = (EditText) v.findViewById(R.id.ed_ycs_csqx);
        // 乙型肝炎五项
        mgv_yxgybmky = (MyGridView) v.findViewById(R.id.mgv_yxgybmky);
        mgv_yxgybmkt = (MyGridView) v.findViewById(R.id.mgv_yxgybmkt);
        mgv_yxgyeky = (MyGridView) v.findViewById(R.id.mgv_yxgyeky);
        mgv_yxgyekt = (MyGridView) v.findViewById(R.id.mgv_yxgyekt);
        mgv_yxgyhxkt = (MyGridView) v.findViewById(R.id.mgv_yxgyhxkt);
        btn_cal_bmi = (Button) v.findViewById(R.id.btn_cal_bmi);
        tv_cc = (TextView) v.findViewById(R.id.tv_cc);

        ed_mcyj_date.showDialog(false);


    }

    /**
     * 绑定数据值
     *
     * @param str_where
     * @param flag
     * @author 王婷婷
     * @date 2015年12月17日 上午10:30:30
     */
    private void bindDdata(String flag, String str_where) {
        List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                str_where + " order by cast(SORT as int) asc");
        if (flag.equals("梅毒血清试验")) {
            List<BD_DD_INFO> listmdxq_new = new ArrayList<BD_DD_INFO>();
            int size = listZZs.size();
            if (size > 0) {
                for (int i = 0; i < size; i++) {

                    // DM06-7_0 0 阴性 /DM06-7_1 1 阳性 /DM06-7_2 2 清空
                    if (listZZs.get(i).getID().equals("DM06-7_0") || listZZs.get(i).getID().equals("DM06-7_1")) {
                        listmdxq_new.add(listZZs.get(i));
                    }
                }
            }
            adapter_mdxqsy = new RadioButtonAdapter(listmdxq_new, getActivity());
            gd_mdxqsy.setAdapter(adapter_mdxqsy);
        } else if (flag.equals("乙型肝炎五项")) {

            adapter_yxgybmky = new RadioButtonAdapter(listZZs, getActivity());
            adapter_yxgybmkt = new RadioButtonAdapter(listZZs, getActivity());
            adapter_yxgyeky = new RadioButtonAdapter(listZZs, getActivity());
            adapter_yxgyekt = new RadioButtonAdapter(listZZs, getActivity());
            adapter_yxgyhxkt = new RadioButtonAdapter(listZZs, getActivity());

            mgv_yxgybmky.setAdapter(adapter_yxgybmky);
            mgv_yxgybmkt.setAdapter(adapter_yxgybmkt);
            mgv_yxgyeky.setAdapter(adapter_yxgyeky);
            mgv_yxgyekt.setAdapter(adapter_yxgyekt);
            mgv_yxgyhxkt.setAdapter(adapter_yxgyhxkt);

        } else if (flag.equals("HIV检测")) {
            List<BD_DD_INFO> listhiv_new = new ArrayList<BD_DD_INFO>();
            int size = listZZs.size();
            if (size > 0) {
                for (int i = 0; i < size; i++) {

                    // DM06-8_1 1 阳性 /DM06-8_2 2 不确定 /DM06-8_3 3 清空 /DM06-8_0 0
                    // 阴性
                    if (listZZs.get(i).getID().equals("DM06-8_1") || listZZs.get(i).getID().equals("DM06-8_0")) {
                        listhiv_new.add(listZZs.get(i));
                    }
                }
            }

            adapter_hiv = new RadioButtonAdapter(listhiv_new, getActivity());
            gd_hiv.setAdapter(adapter_hiv);
        } else if (flag.equals("既往史")) {
            adapter_jws = new CheckBoxAdapter(getActivity(), listZZs);
            adapter_jws.setOtherMaxLength(100);
            gd_jws.setAdapter(adapter_jws);
            adapter_jws.notifyDataSetChanged();
        } else if (flag.equals("家族史")) {
//			List<BD_DD_INFO> listjzs_new = new ArrayList<BD_DD_INFO>();
//			int size = listZZs.size();
//			if (size > 0) {
//				for (int i = 0; i < size; i++) {
//
//					// DM01-24_1 遗传性疾病史、DM01-24_2 精神疾病史 、 DM01-24_3 其他
//					// 、DM01-24_4 无
//					if (listZZs.get(i).getID().equals("DM01-24_1") || listZZs.get(i).getID().equals("DM01-24_2")
//							|| listZZs.get(i).getID().equals("DM01-24_3")) {
//						listjzs_new.add(listZZs.get(i));
//					}
//				}
//			}
            adapter_jzs = new CheckBoxAdapter(getActivity(), listZZs);
            adapter_jzs.setOtherMaxLength(100);
            gd_jzs.setAdapter(adapter_jzs);
        } else if (flag.equals("个人史")) {
            adapter_grs = new CheckBoxAdapter(getActivity(), listZZs);
            adapter_grs.setOtherMaxLength(100);
            gd_grs.setAdapter(adapter_grs);
        } else if (flag.equals("妇科手术史")) {
            adapter_fksss = new RadioButtonAdapter(listZZs, getActivity());
            adapter_fksss.setOtherMaxLength(50);
            gd_fksss.setAdapter(adapter_fksss);
        } else if (flag.equals("阴道分泌物")) {
            adapter_ydfmw = new CheckBoxAdapter(getActivity(), listZZs);
            adapter_ydfmw.setOtherMaxLength(50);
            gd_ydfmw.setAdapter(adapter_ydfmw);
        } else if (flag.equals("总体评估")) {
            adapter_ztpg = new RadioButtonAdapter(listZZs, getActivity());
            adapter_ztpg.setOtherMaxLength(50);
            gd_ztpg.setAdapter(adapter_ztpg);

            adapter_xz = new RadioButtonAdapter(listZZs, getActivity());
            adapter_xz.setOtherMaxLength(50);
            gd_xz.setAdapter(adapter_xz);

            adapter_fb = new RadioButtonAdapter(listZZs, getActivity());
            adapter_fb.setOtherMaxLength(50);
            gd_fb.setAdapter(adapter_fb);

            adapter_wy = new RadioButtonAdapter(listZZs, getActivity());
            adapter_wy.setOtherMaxLength(50);
            gd_wy.setAdapter(adapter_wy);

            adapter_yd = new RadioButtonAdapter(listZZs, getActivity());
            adapter_yd.setOtherMaxLength(50);
            gd_yd.setAdapter(adapter_yd);
            adapter_yd.notifyDataSetChanged();

            adapter_gj = new RadioButtonAdapter(listZZs, getActivity());
            adapter_gj.setOtherMaxLength(50);
            gd_gj.setAdapter(adapter_gj);
            adapter_zg = new RadioButtonAdapter(listZZs, getActivity());
            adapter_zg.setOtherMaxLength(50);
            gd_zg.setAdapter(adapter_zg);
            adapter_fj = new RadioButtonAdapter(listZZs, getActivity());
            adapter_fj.setOtherMaxLength(50);
            gd_fj.setAdapter(adapter_fj);
        } else if (flag.equals("保健指导")) {
            List<BD_DD_INFO> listZZs_new = new ArrayList<BD_DD_INFO>();
            int size = listZZs.size();
            if (size > 0) {
                for (int i = 0; i < size; i++) {

                    // DM06-03_15 生活方式、个人卫生 DM06-03_1 、 心理 DM06-03_2 、营养DM06-03_14、运动
                    // DM06-03_6、其他 DM06-03_99
                    if (listZZs.get(i).getID().equals("DM06-03_15") || listZZs.get(i).getID().equals("DM06-03_2")
                            || listZZs.get(i).getID().equals("DM06-03_14") || listZZs.get(i).getID().equals("DM06-03_4")
                            || listZZs.get(i).getID().equals("DM06-03_5")
                            || listZZs.get(i).getID().equals("DM06-03_99")) {
                        listZZs_new.add(listZZs.get(i));
                    }
                }
            }
            adapter_bjzd = new CheckBoxAdapter(getActivity(), listZZs_new);
            adapter_bjzd.setOtherMaxLength(50);
            gd_bjzd.setAdapter(adapter_bjzd);
        }
    }

    /**
     * 设置下拉
     *
     * @param flagName
     * @param strSql
     * @author 王婷婷
     * @date 2015年12月24日 上午9:19:28
     */
    private void bindSpinner(String flagName, String strSql) {
        List<BD_DD_INFO> sList = new ArrayList<BD_DD_INFO>();
        BD_DD_INFO bd = new BD_DD_INFO();
        bd.setDATAINFO("请选择");
        bd.setID("");
        sList.add(bd);
        List<BD_DD_INFO> sList1 = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
                strSql + " order by cast(SORT as int) asc");
        sList.addAll(sList1);
        if (flagName.equals("阴道清洁度")) {
            qjd_list = sList;
            nice_spinner_ydqjd.attachDataSource(qjd_list);

        }

    }

    @Override
    public void save() {

        checkFetusTime();
        String str_yz = ed_zq.getText().toString();
        if (TextUtils.isEmpty(str_yz)) {
            ed_zq.setBackgroundColor(Color.YELLOW);
            ((MaternityActivity) getActivity()).showTextDialog("请填写孕周");
            return;
        } else {
            if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_zq, 49, 0)) {
                ed_zq.setBackgroundColor(Color.YELLOW);
                ((MaternityActivity) getActivity()).showTextDialog("孕周数据不合理，保存失败");
                return;
            }
            ed_zq.setBackgroundColor(Color.WHITE);
        }


        String str_ycfm = ed_ycfm.getText().toString();
        if (TextUtils.isEmpty(str_ycfm)) {
            ed_ycfm.setBackgroundColor(Color.YELLOW);
            ((MaternityActivity) getActivity()).showTextDialog("请填写孕次");
            return;
        } else {
            if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_ycfm, 49, 0)) {
                ed_ycfm.setBackgroundColor(Color.YELLOW);
                ((MaternityActivity) getActivity()).showTextDialog("孕次数据不合理，保存失败");
                return;
            }
            ed_ycfm.setBackgroundColor(Color.WHITE);
        }


        String str_ycq = ed_ycq_date.getText().toString();
        if (TextUtils.isEmpty(str_ycq)) {
            ed_ycq_date.setBackgroundColor(Color.YELLOW);
            ((MaternityActivity) getActivity()).showTextDialog("请选择预产期");
            return;
        } else {
            ed_ycq_date.setBackgroundColor(Color.WHITE);
        }

        // 身高
        String HEIGHT = ed_sg.getText().toString();
        if (TextUtils.isEmpty(HEIGHT)) {
            ed_sg.setBackgroundColor(Color.YELLOW);
            ((MaternityActivity) getActivity()).showTextDialog("请填写身高");
            return;
        } else {
            if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_sg, 300, 1)) {
                ed_sg.setBackgroundColor(Color.YELLOW);
                ((MaternityActivity) getActivity()).showTextDialog("身高数据不合理，保存失败");
                return;
            }
            ed_sg.setBackgroundColor(Color.WHITE);
        }

        // 体重
        String WEIGHT = ed_weight.getText().toString();
        if (TextUtils.isEmpty(WEIGHT)) {
            ed_weight.setBackgroundColor(Color.YELLOW);
            ((MaternityActivity) getActivity()).showTextDialog("请填写体重");
            return;
        } else {
            if (!GlobalConts.getCheckNumBoolean(getActivity(), ed_weight, 100, 1, 999)) {
                ed_weight.setBackgroundColor(Color.YELLOW);
                ((MaternityActivity) getActivity()).showTextDialog("体重数据不合理，保存失败");
                return;
            }
            ed_weight.setBackgroundColor(Color.WHITE);
        }

        String ncg = ed_jcg.getText().toString();
        if (!TextUtils.isEmpty(ncg)) {
            if (ncg.contains("/")) {
                String[] ncgs = ncg.split("/");
                if (ncgs.length == 4) {


                } else {
                    ((MaternityActivity) getActivity()).showTextDialog("请输入正确的尿常规数据");
                    ed_jcg.setBackgroundColor(Color.RED);
                    return;
                }
            } else {
                ((MaternityActivity) getActivity()).showTextDialog("请输入正确的尿常规数据");
                ed_jcg.setBackgroundColor(Color.RED);
                return;
            }
        }
        setBMI();

        if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_ydfw, 49, 0)) {
            ((MaternityActivity) getActivity()).showTextDialog("阴道分娩数据不合理，保存失败");
            return;
        }
        if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_pgc, 49, 0)) {
            ((MaternityActivity) getActivity()).showTextDialog("剖腹产数据不合理，保存失败");
            return;
        }
        if (!GlobalConts.getCheckNumOrangeBoolean(getActivity(), ed_sg, 300, 1)) {
            ((MaternityActivity) getActivity()).showTextDialog("身高数据不合理，保存失败");
            return;
        }
        if (!GlobalConts.getCheckNumBoolean(getActivity(), ed_weight, 100, 1, 999)) {
            ((MaternityActivity) getActivity()).showTextDialog("体重数据不合理，保存失败");
            return;
        }


        //下次随访时间
        String str_xcsfsj = ed_xcsfsj.getText().toString();
        if (TextUtils.isEmpty(str_xcsfsj)) {
            ed_xcsfsj.setBackgroundColor(Color.YELLOW);
            ((MaternityActivity) getActivity()).showTextDialog("请选择下次随访时间");
            return;
        } else {
            ed_xcsfsj.setBackgroundColor(Color.WHITE);
        }

        // getRadioButtonCheckedData();
        // getCheckBoxedData();
        saveData_followup();
    }

    /**
     * 初始化随访辅助检查
     *
     * @author 鹿云龙
     * @date 2016年1月11日 下午3:50:16
     */
    private void init2() {
        setBloodRh();
        GRAVIDA_PRE_ASSISTCHECK gpa = new GRAVIDA_PRE_ASSISTCHECK();

        List<GRAVIDA_PRE_ASSISTCHECK> gpas = FDbManager.getInstance(getActivity())
                .findAllByWhere(GRAVIDA_PRE_ASSISTCHECK.class, "IDCARD = '" + userInfo.getIDCARD() + "'");
        if (gpas.size() > 0) {
            from2 = 1;
            gpa = gpas.get(gpas.size() - 1);
            // gpa.setARCHIVEID(userInfo.getARCHIVEID());

            ed_zhdhs.setText(gpa.getCB());
            ed_bc.setText(gpa.getBCHAO());// ed_bc.getText().toString());
            // gpa.getBLD(ed);//尿潜血
            ed_xcg_qt.setText(gpa.getBLOOD_OTHER());// ed_xcg_qt.getText().toString());


            // ed_xx.setText(gpa.getBLOODTYPE());// ed_xx.getText().toString());
            ed_xdb.setText(gpa.getBP());// strxdb.isEmpty()
            ed_xnsd.setText(gpa.getBUN());// strXnsd.isEmpty()
            ed_zdhs.setText(gpa.getTBIL());// strjhdhs.isEmpty()
            ed_xt.setText(gpa.getFPGL());// strxt.isEmpty()
            ed_xqgczam.setText(gpa.getGOT());// strgot.isEmpty()
            // String strxhdb = ed_xhdbz.getText().toString();
            ed_xhdbz.setText(gpa.getHB());// strxhdb.isEmpty()
            // 尿蛋白/ 尿糖/ 尿酮体/ 尿潜血
            if (gpa.getPRO() != null && gpa.getGLU() != null && gpa.getKET() != null && gpa.getBLD() != null) {
                ed_jcg.setText(gpa.getPRO() + "/" + gpa.getGLU() + "/" + gpa.getKET() + "/" + gpa.getBLD());
            }

            adapter_yxgyhxkt.setChecked(gpa.getHBCAB());// 乙型肝炎核心抗体
            adapter_yxgyekt.setChecked(gpa.getHBEAB());// 乙型肝炎e抗体
            adapter_yxgyeky.setChecked(gpa.getHBEAG());// 乙型肝炎e抗原
            adapter_yxgybmkt.setChecked(gpa.getHBSAB());// 乙型肝炎表面抗体
            adapter_yxgybmky.setChecked(gpa.getHBSAG());// 乙型肝炎表面抗原
            adapter_hiv.setChecked(gpa.getHIV());

            adapter_mdxqsy.setChecked(gpa.getLUES());
            ed_xxb.setText(gpa.getPLT());// strXxb.isEmpty()
            ed_xqjg.setText(gpa.getSCR());// strxqjg.isEmpty()
            ed_xqgbzam.setText(gpa.getSGPT());// strxqgbzam.isEmpty()
            ed_zdhs.setText(gpa.getTBIL());// strzdhs.isEmpty()
            ed_jcg_qt.setText(gpa.getURINE_OTHERS());// ed_jcg_qt.getText().toString());
            nice_spinner_ydqjd.setSelectedIndex(getDataInfoIndex(gpa.getVAGINALCLEAESS(), qjd_list));// .get(nice_spinner_ydqjd.getSelectedIndex()).getID());
            adapter_ydfmw.setChecked(gpa.getVAGINALSECRETIONS());// adapter_ydfmw.getCheckedIdsStr());
            adapter_ydfmw.setOther(gpa.getVAGINALSECRETIONSOTHERS());// adapter_ydfmw.getOther());
            ed_bxb.setText(gpa.getWBC());// strbxb.isEmpty()
        }
    }

    private int getDataInfoIndex(String id, List<BD_DD_INFO> list) {
        if (TextUtils.isEmpty(id)) {
            return 0;
        }
        for (int i = 0; i < list.size(); i++) {
            if (id.equals(list.get(i).getID())) {
                return i;
            }
        }
        return 0;
    }

    /**
     * 保存数据
     *
     * @author 王婷婷
     * @date 2015年12月17日 上午11:13:39
     */
    private void saveData_followup() {

        GRAVIDA_FIRSTFOLLOWUP ques = new GRAVIDA_FIRSTFOLLOWUP();

        ques.setDEADFETUS(ed_ycs_st.getText().toString());

        ques.setIDCARD(userInfo.getIDCARD());
        ques.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
        ques.setIS_DEL("N");

        ques.setABORTIONINFO(TextUtils.isEmpty(ed_ycs_zrlc.getText()) ? "" : ed_ycs_zrlc.getText().toString());
        ques.setInducedABORTIONINFO(TextUtils.isEmpty(ed_ycs_rglc.getText()) ? "" : ed_ycs_rglc.getText().toString());
        ques.setATTACH(adapter_fj.getChecked());
        ques.setATTACH_EX(adapter_fj.getCheckedOther());
        String strBmi = ed_bmi.getText().toString();
        ques.setBMI(strBmi);
        String strPgc = ed_pgc.getText().toString();
        ques.setCAESAREANCOUNT(strPgc);
        ques.setCERVIXUTERI(adapter_gj.getChecked());
        ques.setCERVIXUTERI_EX(adapter_gj.getCheckedOther());
        ques.setCORPUS(adapter_zg.getChecked());
        ques.setCORPUS_EX(adapter_zg.getCheckedOther());
        ques.setCUSTOMER_AGE(ed_age.getText().toString());
        ques.setCUSTOMERHISTORY(adapter_jws.getCheckedIdsStr());
        ques.setCUSTOMERHISTORY_EX(adapter_jws.getOther());
        ques.setCUSTOMERID(userInfo.getID() + "");
        // ques.setDEADFETUS(ed);
        try {
            String str_ycq = ed_ycq_date.getText().toString();
            if (!TextUtils.isEmpty(str_ycq)) {
                ques.setEXPECTEDDUE_DATE(dateFormat.parse(str_ycq));
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }
        ques.setFAMILYHISTORY(adapter_jzs.getCheckedIdsStr());
        ques.setFAMILYHISTORY_EX(adapter_jzs.getOther());
        ques.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
        ques.setGYNECOLOGYHISTORY(adapter_fksss.getChecked());
        ques.setGYNECOLOGYHISTORY_EX(adapter_fksss.getCheckedOther());
        // ques.setHBLOODPRESSURE(ed_xy);
        String stsrsr = adapter_bjzd.getCheckedIdsStr();
        ques.setHEALTHZHIDAO(stsrsr);// 保健指导
        String bjsdsdf = adapter_bjzd.getOther();
        ques.setHEALTHZHIDAOOTHERS(bjsdsdf);
        ques.setHEART(adapter_xz.getChecked());
        ques.setHEART_EX(adapter_xz.getCheckedOther());
        String strSg = ed_sg.getText().toString();
        ques.setHEIGHT(strSg);
        String strZfnl = ed_zfnl.getText().toString();
        ques.setHUSBAND_AGE(strZfnl);
        ques.setHUSBAND_NAME(ed_zfxm.getText().toString());
        ques.setHUSBAND_PHONE(ed_zfdh.getText().toString());
        ques.setIS_DEL("N");

        try {
            ques.setLAST_UPDATE_DATE(dateFormat.parse(dateFormat.format(new Date())));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        if (rb_mq.isChecked()) {
            str_mcyjId = "DM06-2_0";
        } else if (rb_bx.isChecked()) {
            str_mcyjId = "DM06-2_2";
        } else {
            str_mcyjId = "";
        }

        ques.setLASTMENSTRUATION(str_mcyjId);
        // try {
        // ques.setLASTMENSTRUATION_DATE(dateFormat.parse(ed_mcyj_date.getText().toString()));
        // } catch (ParseException e) {
        // e.printStackTrace();
        // }
        try {
            ques.setLASTMENSTRUATION_DATE(dateFormat.parse(ed_mcyj_date.getText().toString()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String str_xy = ed_xy.getText().toString();
        try {
            if (!TextUtils.isEmpty(str_xy)) {
                if (str_xy.contains("/")) {
                    ques.setHBLOODPRESSURE(str_xy.split("/")[0]);// 收缩压
                    ques.setLBLOODPRESSURE(str_xy.split("/")[1]);// 舒张压
                } else {
                    ques.setHBLOODPRESSURE("");// 收缩压
                    ques.setLBLOODPRESSURE("");// 舒张压
                }
            } else {
                ques.setHBLOODPRESSURE("");// 收缩压
                ques.setLBLOODPRESSURE("");// 舒张压
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        ques.setLUNG(adapter_fb.getChecked());
        ques.setLUNG_EX(adapter_fb.getCheckedOther());
        String strYdfm = ed_ydfw.getText().toString();
        ques.setNATRUALCHILDBIRTHCOUNT(strYdfm);
        ques.setNEWBORNDEAD(ed_ycs_xsesw.getText().toString());
        ques.setNEWBORNDEFECT(ed_ycs_csqx.getText().toString());

        try {
            ques.setNEXTFOLLOWUP_DATE(dateFormat.parse(ed_xcsfsj.getText().toString()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        ques.setOVERALASSESSMENT(adapter_ztpg.getChecked());
        ques.setOVERALASSESSMENT_EX(adapter_ztpg.getCheckedOther());
        ques.setPERSONALHISTORY(adapter_grs.getCheckedIdsStr());
        ques.setPERSONALHISTORY_EX(adapter_grs.getOther());
        String strYc = ed_ycfm.getText().toString();
        ques.setPREGANCY_COUNT(strYc);
        String strYz = ed_zq.getText().toString();
        ques.setPREGANCY_WEEKS(strYz);
        try {
            ques.setRECORD_DATE(dateFormat.parse(ed_date.getText().toString()));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        if (rb_w.isChecked()) {
            str_zzId = "DM01-11_1";
        } else if (rb_y.isChecked()) {
            str_zzId = "DM01-11_2";
        } else {
            str_zzId = "";
        }

        ques.setREFERRAL(str_zzId);
        ques.setREFERRALREASON(ed_zzyy.getText().toString());
        ques.setREFERRALORG(ed_jg_ys.getText().toString());

        ques.setSTILLBIRTHINFO(ed_ycs_sw.getText().toString());
        ques.setVAGINA(adapter_yd.getChecked());
        ques.setVAGINA_EX(adapter_yd.getCheckedOther());
        ques.setVULVA(adapter_wy.getChecked());
        ques.setVULVA_EX(adapter_wy.getCheckedOther());
        String strWeight = ed_weight.getText().toString();
        ques.setWEIGHT(strWeight);

        if (from == 0) {
            ques.setCREATED_BY(userInfo.getCREATED_BY());
            ques.setCREATED_DATE(new Date());
            ques.setCREATEORG(userInfo.getCREATEORG());
            ques.setCREATER(userInfo.getCREATER());

            FDbManager.getInstance(getActivity()).save(ques);
            from = 1;
        } else {
            ques.setLAST_UPDATE_DATE(new Date());
            ques.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
            ques.setUPDATEORG(userInfo.getCREATEORG());
            ques.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
            FDbManager.getInstance(getActivity()).updata(ques, "IDCARD='" + userInfo.getIDCARD() + "'");
        }

        //// 辅助
        GRAVIDA_PRE_ASSISTCHECK gpa = new GRAVIDA_PRE_ASSISTCHECK();
        gpa.setIDCARD(userInfo.getIDCARD());
        gpa.setARCHIVEID("");
        gpa.setBCHAO(ed_bc.getText().toString());
        // gpa.setBLD(ed);//尿潜血
        gpa.setBLOOD_OTHER(ed_xcg_qt.getText().toString());
        gpa.setBLOODTYPE(xxId);
        String strxdb = ed_xdb.getText().toString();
        gpa.setBP(strxdb);
        String strXnsd = ed_xnsd.getText().toString();
        gpa.setBUN(strXnsd);
        String strjhdhs = ed_zdhs.getText().toString();
        gpa.setTBIL(strjhdhs);
        gpa.setCUSTOMERID(userInfo.getCUSTOMERID());
        // gpa.setFOLLOWUPID(userInfo.getf);
        gpa.setFPGL(ed_xt.getText().toString());
        // String strnt = ed_n
        // gpa.setGLU(gLU);//尿糖
        String strgot = ed_xqgczam.getText().toString();
        gpa.setGOT(strgot);
        String strxhdb = ed_xhdbz.getText().toString();
        gpa.setHB(strxhdb);
        // gpa.setHBCAB(gdy);//乙型肝炎核心抗体DM06-11
        // gpa.setHBEAB(hBEAB);//乙型肝炎e抗体DM06-11
        // gpa.setHBEAG(hBEAG);//乙型肝炎e抗原DM06-11
        // gpa.setHBSAB(hBSAB);//乙型肝炎表面抗体DM06-11
        // gpa.setHBSAG(hBSAG);//乙型肝炎表面抗原DM06-11
        gpa.setHIV(adapter_hiv.getChecked());

        // gpa.setID(iD);
        gpa.setIS_DEL("N");
        // gpa.setKET(edn);尿酮体
        // gpa.setLAST_UPDATE_BY(userInfo.getID());
        String ncg = ed_jcg.getText().toString();
        if (!ncg.isEmpty()) {
            if (ncg.contains("/")) {
                String[] ncgs = ncg.split("/");
                if (ncgs.length == 4) {
                    gpa.setPRO(ncgs[0]);// 尿蛋白
                    gpa.setGLU(ncgs[1]);// 尿糖
                    gpa.setKET(ncgs[2]);// 尿酮体
                    gpa.setBLD(ncgs[3]);// 尿潜血
                }
            }
        }
        try {
            gpa.setLAST_UPDATE_DATE(dateFormat.parse(dateFormat.format(new Date())));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        // gpa.setLUES(rd_mcyj);gd_mdxqsy//梅毒血清
        gpa.setLUES(adapter_mdxqsy.getChecked());
        String strXxb = ed_xxb.getText().toString();
        gpa.setPLT(strXxb);//
        // gpa.setPRO(e);
        gpa.setRH(rhId);
        String strxqjg = ed_xqjg.getText().toString();
        gpa.setSCR(strxqjg);
        String strxqgbzam = ed_xqgbzam.getText().toString();
        gpa.setSGPT(strxqgbzam);
        String strzdhs = ed_zdhs.getText().toString();
        gpa.setTBIL(strzdhs);
        gpa.setURINE_OTHERS(ed_jcg_qt.getText().toString());
        if (qjd_list.size() > 0) {
            gpa.setVAGINALCLEAESS(qjd_list.get(nice_spinner_ydqjd.getSelectedIndex()).getID());
        }
        gpa.setVAGINALSECRETIONS(adapter_ydfmw.getCheckedIdsStr());
        gpa.setVAGINALSECRETIONSOTHERS(adapter_ydfmw.getOther());
        String strbxb = ed_bxb.getText().toString();
        gpa.setWBC(strbxb);

        gpa.setHBCAB(adapter_yxgyhxkt.getChecked());// 乙型肝炎核心抗体
        gpa.setHBEAB(adapter_yxgyekt.getChecked());// 乙型肝炎e抗体
        gpa.setHBEAG(adapter_yxgyeky.getChecked());// 乙型肝炎e抗原
        gpa.setHBSAB(adapter_yxgybmkt.getChecked());// 乙型肝炎表面抗体
        gpa.setHBSAG(adapter_yxgybmky.getChecked());// 乙型肝炎表面抗原
        String str = ed_zhdhs.getText().toString();
        gpa.setCB(str);
        if (from2 == 0) {
            gpa.setLAST_UPDATE_DATE(new Date());
            gpa.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
            gpa.setCREATED_BY(userInfo.getCREATED_BY());
            gpa.setCREATED_DATE(new Date());
            gpa.setCREATEORG(userInfo.getCREATEORG());
            gpa.setCREATER(userInfo.getCREATER());
            FDbManager.getInstance(getActivity()).save(gpa);
            from2 = 1;
        } else {
            gpa.setLAST_UPDATE_DATE(new Date());
            gpa.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
            gpa.setUPDATEORG(userInfo.getCREATEORG());
            gpa.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
            FDbManager.getInstance(getActivity()).updata(gpa, "IDCARD='" + userInfo.getIDCARD() + "'");
        }

//		((MaternityActivity) getActivity()).showTextDialog("保存成功");
        if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
            new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
                            intent.putExtra("type", "03");
                            intent.putExtra("szfs", "");
                            startActivity(intent);
                        }
                    }).show();
        } else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
            ((MaternityActivity) getActivity()).showTextDialog("保存成功");
        }
    }

    private int from2 = 0;

    // /**
    // * 获取转诊的信息
    // *
    // * @author 王婷婷
    // * @date 2015年12月16日 下午3:10:48
    // */
    // private void getRadioButtonCheckedData() {
    //
    // str_fksssId = adapter_fksss.getChecked();
    // str_fksssContent = adapter_fksss.getCheckedOther();
    // str_xzId = adapter_fksss.getChecked();
    // str_xzContent = adapter_xz.getCheckedOther();
    // str_fbId = adapter_fksss.getChecked();
    // str_fbContent = adapter_fb.getCheckedOther();
    // str_wyId = adapter_fksss.getChecked();
    // str_wyContent = adapter_wy.getCheckedOther();
    //
    // str_ydId = adapter_fksss.getChecked();
    // str_ydContent = adapter_yd.getCheckedOther();
    //
    // str_gjId = adapter_fksss.getChecked();
    // str_gjContent = adapter_gj.getCheckedOther();
    // str_zgId = adapter_fksss.getChecked();
    // str_zgContent = adapter_zg.getCheckedOther();
    // str_fjId = adapter_fksss.getChecked();
    // str_fjContent = adapter_fj.getCheckedOther();
    //
    // }
    //
    // /**
    // * 获取 被选中的checkbox
    // *
    // * @author 王婷婷
    // * @date 2015年12月19日 上午11:34:30
    // */
    // private void getCheckBoxedData() {
    // str_jwsId = adapter_jws.getCheckedIdsStr();
    // str_jwsContent = adapter_jws.getOther();
    // str_jzsId = adapter_jzs.getCheckedIdsStr();
    // str_jzsContent = adapter_jzs.getOther();
    // str_grsId = adapter_grs.getCheckedIdsStr();
    // str_grsContent = adapter_grs.getOther();
    // str_ydfmwId = adapter_ydfmw.getCheckedIdsStr();
    // str_ydfmwContent = adapter_ydfmw.getOther();
    // str_zhidaoId = adapter_bjzd.getCheckedIdsStr();
    // str_zhidaoContent = adapter_bjzd.getOther();
    //
    // }

    private int from = 0;

    private void init() {

        GRAVIDA_FIRSTFOLLOWUP ques = new GRAVIDA_FIRSTFOLLOWUP();
        List<GRAVIDA_FIRSTFOLLOWUP> quess = FDbManager.getInstance(getActivity())
                .findAllByWhere(GRAVIDA_FIRSTFOLLOWUP.class, "IDCARD = '" + userInfo.getIDCARD() + "'");
        if (quess.size() > 0) {
            from = 1;
            ques = quess.get(quess.size() - 1);
            ed_ycs_st.setText(ques.getDEADFETUS());

            str_zzId = ques.getREFERRAL();

            if (!TextUtils.isEmpty(str_zzId)) {
                if (str_zzId.equals("DM01-11_1")) {
                    rb_w.setChecked(true);
                } else if (str_zzId.equals("DM01-11_2")) {
                    rb_y.setChecked(true);
                }
            }

            ed_zzyy.setText(ques.getREFERRALREASON());
            ed_jg_ys.setText(ques.getREFERRALORG());

            ed_age.setText(ques.getCUSTOMER_AGE());
            for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
                if (ques.getFOLLOWUPDOCTOR().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
                    ed_sfysqm.setSelectedIndex(i);
                }

            }
            ed_ycs_zrlc.setText(ques.getABORTIONINFO());
            ed_ycs_rglc.setText(ques.getInducedABORTIONINFO());
            adapter_fj.setChecked(ques.getATTACH(), ques.getATTACH_EX());
            ed_bmi.setText(ques.getBMI() + "");
            ed_pgc.setText(ques.getCAESAREANCOUNT() + "");
            adapter_gj.setChecked(ques.getCERVIXUTERI(), ques.getCERVIXUTERI_EX());
            adapter_zg.setChecked(ques.getCORPUS(), ques.getCORPUS_EX());
            adapter_jws.setChecked(ques.getCUSTOMERHISTORY());
            adapter_jws.setOther(ques.getCUSTOMERHISTORY_EX());
            adapter_jzs.setChecked(ques.getFAMILYHISTORY());
            adapter_jzs.setOther(ques.getFAMILYHISTORY_EX());
            adapter_fksss.setChecked(ques.getGYNECOLOGYHISTORY(), ques.getGYNECOLOGYHISTORY_EX());
            adapter_bjzd.setChecked(ques.getHEALTHZHIDAO());
            String ssdfffd = ques.getHEALTHZHIDAOOTHERS();
            adapter_bjzd.setOther(ssdfffd);
            adapter_xz.setChecked(ques.getHEART(), ques.getHEART_EX());
            ed_sg.setText(ques.getHEIGHT() + "");

            try {
                Date ycq_date = ques.getEXPECTEDDUE_DATE();
                if (ycq_date != null) {
                    ed_ycq_date.setText(dateFormat.format(ycq_date));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (gravida_baseInfo != null) {
                ed_zfnl.setText(gravida_baseInfo.getHUSBANDAGE());
                ed_zfxm.setText(gravida_baseInfo.getHUSBAND_NAME());
                ed_zfdh.setText(gravida_baseInfo.getHUSBAND_PHONE());
                // ed_zfnl.setText(ques.getHUSBAND_AGE() + "");
                // ed_zfxm.setText(ques.getHUSBAND_NAME());
                // ed_zfdh.setText(ques.getHUSBAND_PHONE());
            }

            str_mcyjId = ques.getLASTMENSTRUATION();

            if (!TextUtils.isEmpty(str_mcyjId)) {
                if (str_mcyjId.equals("DM06-2_0")) {
                    rb_mq.setChecked(true);
                } else if (str_mcyjId.equals("DM06-2_2")) {
                    rb_bx.setChecked(true);
                }
            }

            try {
                Date mcyjsj = ques.getLASTMENSTRUATION_DATE();
                if (mcyjsj != null) {
                    ed_mcyj_date.setText(dateFormat.format(mcyjsj));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            String sys_ss = ques.getHBLOODPRESSURE();
            if (!TextUtils.isEmpty(sys_ss)) {
                String sys_sz = ques.getLBLOODPRESSURE();
                String str_sy = sys_ss + "/" + sys_sz;
                ed_xy.setText(str_sy);
            }

            adapter_fb.setChecked(ques.getLUNG(), ques.getLUNG_EX());
            ed_ydfw.setText(ques.getNATRUALCHILDBIRTHCOUNT() + "");
            ed_ycs_xsesw.setText(ques.getNEWBORNDEAD());
            ed_ycs_csqx.setText(ques.getNEWBORNDEFECT());

            try {
                Date dxcsfsj = ques.getNEXTFOLLOWUP_DATE();
                if (dxcsfsj != null) {
                    ed_xcsfsj.setText(dateFormat.format(dxcsfsj));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            adapter_ztpg.setChecked(ques.getOVERALASSESSMENT(), ques.getOVERALASSESSMENT_EX());
            adapter_grs.setChecked(ques.getPERSONALHISTORY());
            adapter_grs.setOther(ques.getPERSONALHISTORY_EX());
            ed_ycfm.setText(ques.getPREGANCY_COUNT());
            ed_zq.setText(ques.getPREGANCY_WEEKS());

            try {
                Date dateed = ques.getRECORD_DATE();
                if (dateed != null) {
                    ed_date.setText(dateFormat.format(dateed));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            ed_ycs_sw.setText(ques.getSTILLBIRTHINFO());
            adapter_yd.setChecked(ques.getVAGINA(), ques.getVAGINA_EX());
            adapter_wy.setChecked(ques.getVULVA(), ques.getVULVA_EX());
            adapter_fj.setChecked(ques.getATTACH_EX());
            ed_weight.setText(ques.getWEIGHT() + "");

        } else {
            Date born_time = userInfo.getBIRTHDAY();
            int age = GlobalConts.getAge(born_time);
            if (age != -1) {
                ed_age.setText(String.valueOf(age));
            } else {
                ed_age.setText("");
            }
            for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
                if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
                    ed_sfysqm.setSelectedIndex(i);
                }

            }
            ed_date.setText(dateFormat.format(new Date()));

            if (gravida_baseInfo != null) {
                ed_zfnl.setText(gravida_baseInfo.getHUSBANDAGE());
                ed_zfxm.setText(gravida_baseInfo.getHUSBAND_NAME());
                ed_zfdh.setText(gravida_baseInfo.getHUSBAND_PHONE());
            }

        }
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
        int id = v.getId();
        if (id == R.id.btn_choose_xy) {
            intent.putExtra("flag", BluetoothConstant.XUEYA_TYPENAME);
            getActivity().startActivityForResult(intent, GlobalConts.RequestXueya);
        } else if (id == R.id.btn_choose_weight) {
            intent.putExtra("flag", BluetoothConstant.TIZHONG_TYPENAME);
            getActivity().startActivityForResult(intent, GlobalConts.RequestTizhong);
        } else if (id == R.id.btn_choose_xhdbz) {
            intent.putExtra("flag", "血红蛋白");
            getActivity().startActivityForResult(intent, GlobalConts.RequestXueHongDanbai);
        } else if (id == R.id.btn_choose_jcg) {
            intent.putExtra("flag", BluetoothConstant.NIAOCHANGGUI_TYPENAME);
            getActivity().startActivityForResult(intent, GlobalConts.RequestNiaoChangGui);
        } else if (id == R.id.btn_choose_xt) {
            intent.putExtra("flag", BluetoothConstant.XUETANG_TYPENAME);
            getActivity().startActivityForResult(intent, GlobalConts.RequestXuetang);
        } else if (id == R.id.btn_cal_bmi) {
            setBMI();
        } else {
        }

    }

    @Override
    public void setTizhong(String value) {
        ed_weight.setText(value);
    }

    @Override
    public void setXueya(String gaoya, String diya, String mailv) {
        if (!TextUtils.isEmpty(gaoya) && !TextUtils.isEmpty(diya)) {
            ed_xy.setText(gaoya + "/" + diya);
        }
    }

    @Override
    public void setXueHongDanBai(String xhdb) {
        if (!TextUtils.isEmpty(xhdb)) {
            ed_xhdbz.setText(String.valueOf((int) (Double.parseDouble(xhdb) * 10)));
        }
    }

    @Override
    public void setXuetang(String value) {
        ed_xt.setText(value);
    }

    @Override
    public void setNiaoYeFenxi(String niaoDanYuan, String qianXue, String DanHongSu, String tongti, String puTaoTang,
                               String danBaiZhi, String PH, String yaXiaoSuan, String baiXiBao, String biZhong, String weiShengSu) {
        ed_jcg.setText(danBaiZhi + "/" + puTaoTang + "/" + tongti + "/" + qianXue);
    }

    //设置BMI
    private void setBMI() {
        try {
            if (ed_weight.getText().toString().isEmpty() || ed_sg.getText().toString().isEmpty()) {
                return;
            }
            double dh = Double.parseDouble(ed_sg.getText().toString()) / 100;
            double dw = Double.parseDouble(ed_weight.getText().toString());
            java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
            ed_bmi.setText(df.format(GlobalConts.getBMI(dh, dw)) + "");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 设置血型和rh
     *
     * @author 王婷婷
     * @date 2018年1月12日 上午10:47:20
     */
    private void setBloodRh() {
        if (!TextUtils.isEmpty(userInfo.getBLOODTYPE())) {
            xxId = userInfo.getBLOODTYPE();
            List<BD_DD_INFO> xxBD = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, " ID='" + xxId + "'");
            if (xxBD.size() > 0) {
                ed_xx.setText(xxBD.get(0).getDATAINFO());
            }
        } else {
            xxId = "";
            ed_xx.setText("");
        }

        if (!TextUtils.isEmpty(userInfo.getRH())) {
            rhId = userInfo.getRH();
            List<BD_DD_INFO> rhBD = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, " ID='" + rhId + "'");
            if (rhBD.size() > 0) {
                ed_rh.setText(rhBD.get(0).getDATAINFO());
            }
        } else {
            rhId = "";
            ed_rh.setText("");
        }
    }
}
